package com.lkyh.mes.common.datasource.support;

import lombok.experimental.UtilityClass;
import org.apache.ibatis.mapping.VendorDatabaseIdProvider;

import javax.sql.DataSource;

/**
 * 数据库操作工具类
 * 此工具类目的是为了兼容多个数据库，目前兼容的数据库是mysql和pgsql
 *
 * @author wuganglin
 */
@UtilityClass
public class DataSourceUtils {
	private VendorDatabaseIdProvider databaseIdProvider;
	private DataSource dataSource;

//	public DataSourceFunctionUtils(VendorDatabaseIdProvider databaseIdProvider, DataSource dataSource) {
//		// 初始化
//		this.databaseIdProvider = databaseIdProvider;
//		this.dataSource = dataSource;
//		String databaseId = databaseIdProvider.getDatabaseId(dataSource);
//		DB_TYPE = StringUtils.upperCase(databaseId);
//	}

	/**
	 * 获得当前时间
	 *
	 * @return
	 */
	public String getCurrentTime(String type) {
		String result = "";
		if ("MySQL".equalsIgnoreCase(type)) {
			result = "now()";
		} else if ("PostgreSQL".equalsIgnoreCase(type)) {
			result = "now()";
		} else {

		}
		return result;
	}

	public String getDriverClassName(String url) {
		String result = "com.mysql.cj.jdbc.Driver";
		if (url.contains("postgresql:")) {
			result = "org.postgresql.Driver";
		}
		return result;
	}
}
